package com.vsd.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.demo.domain.UserNotify;
import com.vsd.repository.UserNotifyRepository;
import com.vsd.service.UserNotifyService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 用户服务接口实现
 * 
 * @author jiekechoo
 *
 */
@Service
@Transactional
public class UserNotifyServiceImpl implements UserNotifyService {
	@SuppressWarnings("unused")
	private static final Logger LOGGER = LoggerFactory
			.getLogger(UserNotifyServiceImpl.class);
	
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	@Autowired
	private UserNotifyRepository userNotifyRepository;

	@Override
	public void updateRead(String userId, Integer type) {
		// TODO Auto-generated method stub
		String sql = "update b_user_notify set is_read = 1 where user_id = '"+userId+"' and type="+type;
		jdbcTemplate.execute(sql);
	}
	
	@Override
	public Page<UserNotify> findByUserIdAndType(String userId,Integer type,Pageable p){
		return userNotifyRepository.findByUserIdAndType(userId, type, p);
	}

	@Override
	public void delete(String id) {
		userNotifyRepository.delete(id);
	}

	@Override
	public void deleteByUserIdAndType(String userId, Integer type) {
		String sql = "delete from b_user_notify where user_id = '"+userId+"' and type="+type;
		jdbcTemplate.execute(sql);
	}

	@Override
	public void updateRead(String id) {
		// TODO Auto-generated method stub
		String sql = "update b_user_notify set is_read = 1 where id = '"+id+"'";
		jdbcTemplate.execute(sql);
	}

	@Override
	public UserNotify findOne(String id) {
		// TODO Auto-generated method stub
		return userNotifyRepository.findOne(id);
	}
	
}
